﻿
@{

    Layout = "~/Areas/Intranet/Views/Shared/_Layout2.cshtml";

}

<script type="text/javascript" src="~/Areas/Intranet/ckeditor/ckeditor.js"></script>
<div id="topico" class="topico">@ViewBag.titulo</div>
<div class="box_medio">

    @using (Html.BeginForm(null, null, FormMethod.Post, new { @id = "form", enctype = "multipart/form-data" }))
    {


        @Html.ValidationSummary(true)




        @Html.Hidden("tipo")
        <fieldset id="usuarios" name="usuario">
            <legend class="editor-field">
                <label class="txtLabel">
                    Usuário desejado:
                </label>
            </legend>
            <br />
            @Html.DropDownList("uni_ori_codigo")
            <br />
            <select class="select_medio" id="user_ori_codigo" name="user_ori_codigo" ></select>
        </fieldset>
        <br />


        <fieldset id="usuarios" name="usuarios">
            <legend class="editor-field">
                <label class="txtLabel">
                    Usuário de destino:
                </label>
            </legend>
            <br />

            @Html.DropDownList("uni_dest_codigo")

            <br />
          
            <select class="select_medio" id="user_dest_codigo" name="user_dest_codigo" > </select>
        </fieldset>


        <input id="Salvar" type="submit" value="Copiar" class="btn" />

    }


    @if (ViewBag.res != null)
    {
        @Html.Raw("<script type='text/javascript'>successAlert('Sucesso', '" + ViewBag.res + "');</script>")
    }
    @if (ViewBag.err != null)
    {
        @Html.Raw("<script type='text/javascript'>errorsAlert('Atenção', '" + ViewBag.err + "');</script>")
    }
    
    <script>


        function carrega_usuario_origem()
        {
            $("#user_ori_codigo").empty();
            $.getJSON("GetUsuario", {
                unidade: $("#uni_ori_codigo").val()
            }, function (result) {
                data = $.parseJSON(result);

                $("#user_ori_codigo").append("<option value=-1>Nenhum</option>");
             
                    for (var i = 0; i < data.length; i++) {
                        var item = data[i];
                        $("#user_ori_codigo").append("<option value=" + item.id + ">" + item.desc + "</option>");
                    
                }
          
            });
        }

        function carrega_usuario_destino() {
            $("#user_dest_codigo").empty();
            $.getJSON("GetUsuario", {
                unidade: $("#uni_dest_codigo").val()
            }, function (result) {
                data = $.parseJSON(result);

                    for (var i = 0; i < data.length; i++) {
                        var item = data[i];
                        $("#user_dest_codigo").append("<option value=" + item.id + ">" + item.desc + "</option>");

                }

            });

        }

 
        $().ready(function () {

            carrega_usuario_origem();
            carrega_usuario_destino();
     
            $("#uni_ori_codigo").bind("change", function () {
                carrega_usuario_origem();
            });
               

            $("#uni_dest_codigo").bind("change", function () {
                carrega_usuario_destino();
            });


        });
    </script>
</div>